package pl.edu.agh.neuraleconomy.ui.component;

import java.util.Date;

import lombok.Getter;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

import pl.edu.agh.neuraleconomy.ui.util.UIUtils;

public class ImportDataDialog extends OkCancelDialog{

	@Getter
	private Date dateFrom;
	@Getter
	private Date dateTo;
	
	private DateTime dateFromWidget;
	private DateTime dateToWidget;
	
	public ImportDataDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	protected void init(Composite parent) {
		parent.setLayout(new GridLayout(2, false));
		
		(new Label(parent, SWT.NONE)).setText("Date from");
		dateFromWidget = new DateTime(parent, SWT.DROP_DOWN);
		
		(new Label(parent, SWT.NONE)).setText("Date to");
		dateToWidget = new DateTime(parent, SWT.DROP_DOWN);
		
	}

	@Override
	protected void saveInput() {
		dateFrom = UIUtils.getDateFromDateTimeWidget(dateFromWidget);
		dateTo = UIUtils.getDateFromDateTimeWidget(dateToWidget);
	}

	@Override
	protected boolean validateInput() {
		return UIUtils.getDateFromDateTimeWidget(dateFromWidget).compareTo(UIUtils.getDateFromDateTimeWidget(dateToWidget)) <= 0;
	}
	
	public void setDateFrom(Date dateFrom){
		UIUtils.setDateInDateTimeWidget(dateFromWidget, dateFrom);
	}
	
	public void setDateTo(Date dateTo){
		UIUtils.setDateInDateTimeWidget(dateToWidget, dateTo);
	}

}
